package com.mbigger.admin.common;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.UnauthenticatedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import lombok.extern.slf4j.Slf4j;

@ControllerAdvice
@Slf4j
public class ExceptionHandlers {
	
	@ExceptionHandler(value=UnauthenticatedException.class)
	@ResponseStatus(value=HttpStatus.OK)
	@ResponseBody
	public Map<String, Object> handleException(UnauthenticatedException exception, HttpServletRequest request){
		String msg = exception.getMessage();
		log.error("{}", msg);
		exception.printStackTrace();
		return JsonResultHoler.fail(msg).toMap();
	}
	
	
	@ExceptionHandler(value=Exception.class)
	@ResponseStatus(value=HttpStatus.OK)
	@ResponseBody
	public Map<String, Object> handleException(Exception exception, HttpServletRequest request){
		String msg = exception.getMessage();
		log.error("{}", msg);
		return JsonResultHoler.fail(msg).toMap();
	}
}
